package com.gpframework.module.order.service.impl;

import com.gpframework.common.enums.OrderStatusEnum;
import com.gpframework.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gpframework.module.order.mapper.GpFlowConfigMapper;
import com.gpframework.module.order.domain.GpFlowConfig;
import com.gpframework.module.order.domain.vo.GpFlowConfigVo;
import com.gpframework.module.order.service.IGpFlowConfigService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
/**
 * @ClassName GpFlowConfig
 * @Author gpframework
 * @Date 2023-06-16
 * @Version 1.0.0
 * @Description 流转节点配置Service业务层处理
 */
@Service
public class GpFlowConfigServiceImpl extends ServiceImpl<GpFlowConfigMapper, GpFlowConfig> implements IGpFlowConfigService {

    /**
     * @Description 查询列表返回VO 用于返回给前端的列表接口
     * @Author gpframework
     * @Date 2023-06-16
     * @Param [lqw]
     * @Return List<GpFlowConfigVo>
     */
    @Override
    public List<GpFlowConfigVo> listVo(QueryWrapper<GpFlowConfig> lqw) {
        return this.baseMapper.listVo(lqw);
    }

    /**
     * @Description 通过查询详情VO 用于返回给前端的列详情接口
     * @Author gpframework
     * @Date 2023-06-16
     * @Param [id]
     * @Return GpFlowConfigVo
     */
    @Override
    public GpFlowConfigVo getVoById(Long id) {
        return this.baseMapper.getVo(id);
    }

    @Override
    public List<Long> getOrderStatusByUserId(Long userId) {
        return this.baseMapper.getOrderStatusByUserId(userId);
    }

    /**
     * 获取下一个流转节点
     * @param orderStatus
     * @return
     */
    @Override
    public GpFlowConfig getByOrderStatus(String orderStatus) {
        if (StringUtils.equals(orderStatus, OrderStatusEnum.TO_BE_PICKING_UP_GOODS.getKey())) {
            // 拿货
            return this.getOne(new QueryWrapper<GpFlowConfig>().eq("sort", OrderStatusEnum.PICKING_UP_GOODS.getKey()).orderByAsc("sort").last("limit 1"));
        } else if (StringUtils.equals(orderStatus, OrderStatusEnum.TO_BE_INSPECTION.getKey())) {
            // 验货
            return this.getOne(new QueryWrapper<GpFlowConfig>().eq("sort", OrderStatusEnum.INSPECTION.getKey()).orderByAsc("sort").last("limit 1"));
        } else if (StringUtils.equals(orderStatus, OrderStatusEnum.TO_BE_STOCK_UP.getKey())) {
            // 备货
            return this.getOne(new QueryWrapper<GpFlowConfig>().eq("sort", OrderStatusEnum.STOCK_UP.getKey()).orderByAsc("sort").last("limit 1"));
        } else if (StringUtils.equals(orderStatus, OrderStatusEnum.TO_BE_SEND_OUT_GOODS.getKey())) {
            // 发货
            return this.getOne(new QueryWrapper<GpFlowConfig>().eq("sort", OrderStatusEnum.SEND_OUT_GOODS.getKey()).orderByAsc("sort").last("limit 1"));
        } else if (StringUtils.equals(orderStatus, OrderStatusEnum.TO_BE_TRANSFER.getKey())) {
            // 中转
            return this.getOne(new QueryWrapper<GpFlowConfig>().eq("sort", OrderStatusEnum.TRANSFER.getKey()).orderByAsc("sort").last("limit 1"));
        }
        return null;
    }
}
